GBML manual / Backgrounds

Perspective floor

The zoomable background drawn as a floor that runs away to a horizon, the way a racing game draws its road - set by code, with objects that stand on it, redrawn row by row by the console.

A road that runs to the horizon

A zoomable background normally zooms and turns as one flat picture. With the perspective floor on, the same picture is drawn as a floor seen from a camera standing over it: the part under the camera is large, the part far ahead is small and thin, and it all runs away to a horizon. It is how a racing game draws a track from one big picture, and it works for anything laid flat: a sea, a desert, a battlefield, a corridor.

It is beside the plain zoom, never instead of it. Turn the floor off and the picture is the flat zoomable background again.

Setting it up (GBML only)

There is no room setting and no editor control: the floor is started by code, in the Create event of the object that runs the race.

  1. Give the room a zoomable background (Room Editor, Tile Palette, Backgrounds, the Zoomable tick). The picture is the whole floor, so a 1024 by 1024 picture is a floor 1024 pixels each way. Give the room the picture's size too, so everything standing on the floor is inside it.
  2. In that object's Create event, turn the floor on and set how it looks:
perspective_floor(true);
perspective_floor_horizon(54);
perspective_floor_height(24);
perspective_floor_view(90);
  1. Every frame, move the camera:
perspective_floor_camera(cam_x, cam_y, heading);
CallWhat it sets
perspective_floor_camera(x, y, heading)Where the camera stands on the picture (the picture's own pixels, from its top-left corner) and which way it looks (degrees, 0 looks up the picture, counter-clockwise)
perspective_floor_heightHow high the camera is above the picture. Higher shows more floor and makes the road look smaller
perspective_floor_horizonThe screen row, from the top, where the floor starts. Rows above it show the room's other pictures
perspective_floor_viewHow wide the camera sees across the screen, in degrees. Wide stretches the road sideways

Putting things on the road

Give an object floor places for its x and y: picture pixels. Then everything that works in the room works on the floor, whatever the camera does: collision_rect, masks, dist_to, motion. Put it on the screen from its Draw event:

Set the object's Release off view off (an object outside the screen is otherwise released), and give the room the picture's size.

What it costs, and what to keep in mind

See also: Zoomable backgroundsBackgroundsperspective_floorperspective_floor_cameraperspective_floor_heightperspective_floor_horizonperspective_floor_viewperspective_floor_projectdraw_self_on_floordraw_sprite_on_floorfloor_scale_atperspective_floor_aheadzoom_background_repeatdraw_sprite_scaled